import Vue from 'vue';
import iView from 'iview';
import VueRouter from 'vue-router';
import Routers from './router';
import Util from './libs/util';
import App from './app.vue';
import 'iview/dist/styles/iview.css';
import Vuex from 'vuex';
import resource from 'vue-resource';
import tldAjax from './tld-ajax.js';

Vue.use(Vuex);
Vue.use(VueRouter);
Vue.use(iView);
Vue.use(resource);
Vue.use(tldAjax);

// 路由配置
const RouterConfig = {
	mode: 'history',
	routes: Routers
};
const router = new VueRouter(RouterConfig);

router.beforeEach((to, from, next) => {
	iView.LoadingBar.start();
	Util.title(to.meta.title);
	next();
});

router.afterEach((to, from, next) => {
	iView.LoadingBar.finish();
	window.scrollTo(0, 0);
});

const store = new Vuex.Store({
	state: {
		loading: false
	},
	mutations: {
		increment(state) {
			if(state.loading) {
				state.loading = false
			} else {
				state.loading = true
			}
		}
	}
})

new Vue({
	el: '#app',
	store,
	router: router,
	render: h => h(App)
});